const rob = root => {
  if (root === null) return 0
  let sum = root.val
  if (root.left !== null) {
    sum += (rob(root.left.left) + rob(root.left.right))
  }
  if (root.right !== null) {
    sum += (rob(root.right.left) + rob(root.right.right))
  }
  return Math.max(sum, rob(root.left) + rob(root.right))
}

let root = {
  val: 3,
  left: {
    val: 2,
    left: null,
    right: {
      val: 3,
      left: null,
      right: null
    }
  },
  right: {
    val: 3,
    left: null,
    right: {
      val: 1,
      left: null,
      right: null
    }
  }
}

console.log(rob(root));